package com.tcg.prototype;

import android.R.integer;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

public class PlayerResourcesView extends LinearLayout {

	private int gold;
	private int goldIncome;
	private int mana;
	private int manaIncome;
	
	private TextView goldBar;
	private TextView manaBar;
	
	public PlayerResourcesView(Context context, AttributeSet attrs) {
		super(context, attrs);
		inflate(context, R.layout.player_resources, this);
		
		TypedArray attributes =getContext().obtainStyledAttributes(
		         attrs,
		         R.styleable.PlayerResourcesView);
		
		this.gold = attributes.getInteger(R.styleable.PlayerResourcesView_gold, 0);
		this.goldIncome = attributes.getInteger(R.styleable.PlayerResourcesView_goldIncome, 0);
		this.mana = attributes.getInteger(R.styleable.PlayerResourcesView_mana, 0);
		this.manaIncome = attributes.getInteger(R.styleable.PlayerResourcesView_manaIncome, 0);
		
		attributes.recycle();
		
		goldBar = (TextView) this.findViewById(R.id.player_gold_text);
		manaBar = (TextView) this.findViewById(R.id.player_mana_text);
		
		updateInfo();
	}

	private void updateInfo() {
		goldBar.setText(
				String.format("%d / +%d", gold, goldIncome)
				);
		manaBar.setText(
				String.format("%d / +%d", mana, manaIncome)
				);
		
	}
}
